package com.safe.text;

import com.safe.text.R;
import com.markupartist.android.widget.ActionBar;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SetupActivity extends BaseActivity {

	Button btnSecure;
	EditText etvPhone;
	int phone = 0;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setup);
		currentActivity = this;
		ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
		actionBar.setTitle(R.string.app_name);
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);
		final SharedPreferences.Editor prefsEditor = prefs.edit();
		phoneNumber = prefs.getString("phoneNumber", "");
		emailAddress = prefs.getString("emailAddress", "");
		btnSecure = (Button) findViewById(R.id.btnSecure);
		etvPhone = (EditText) findViewById(R.id.etv_phoneNumber);
		if (phoneNumber != "") {
			etvPhone.setText(prefs.getString("phoneNumber", ""));
		}

		btnSecure.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				phone = etvPhone.getText().length();

				Intent secure = new Intent(SetupActivity.this,
						SecureActivity.class);

				if (phone >= 10) {
					prefsEditor.putString("phoneNumber", etvPhone.getText()
							.toString());
					Intent returnIntent = new Intent();
					setResult(RESULT_CANCELED, returnIntent);
					prefsEditor.commit();
					finish();
					startActivity(secure);
				} else {

					makeToast("Please enter a valid phone number");
				}

			}
		});
	}

	public void onResume() {
		currentActivity = this;
		super.onResume();
	}
}
